package com.du.dao.impl;

import com.du.dao.BaseDAO;
import com.du.dao.BookDAO;
import com.du.pojo.Book;

import java.util.List;

/**
 * @author : DuJiabao
 * @Date : 2021/2/1 22:32
 * @Project : bookstore
 * @File : null.java
 * @Desc :
 */
public class BookDAOImpl extends BaseDAO implements BookDAO {
    @Override
    public Book queryBook(String bookName) {
        return queryForOne(Book.class, "select * from book_list where name=?;", bookName);
    }

    @Override
    public Book queryBook(int id) {
        return queryForOne(Book.class, "select * from book_list where id=?;", id);
    }

    @Override
    public List<Book> queryBookList() {
        return queryForList(Book.class, "select * from book_list;");
    }

    @Override
    public int deleteBook(Book book) {
        return deleteBook(book.getId());
    }

    @Override
    public int deleteBook(String bookName) {
        return update("delete from book_list where name=?", bookName);
    }

    @Override
    public int deleteBook(int id) {
        return update("delete from book_list where id=?", id);
    }

    @Override
    public int updateBook(Book book) {
        return update("update book_list set name=?, price=?, author=?, sales=?, inventory=? where id=?",
                book.getName(), book.getPrice(), book.getAuthor(), book.getSales(), book.getInventory(), book.getId());
    }

    @Override
    public int saveBook(Book book) {
        return update("insert into book_list(name, price, author, sales, inventory) values(?,?,?,?,?)",
                book.getName(), book.getPrice(), book.getAuthor(), book.getSales(), book.getInventory());
    }
}
